using System;
using System.Collections.Generic;
using System.Text;
using PortableDeviceApiLib;
using PortableDeviceConstants;
using ZuneDeviceConstants;

namespace zUnlock
{
    class ZuneComm
    {
        PortableDevice pPortableDevice = new PortableDeviceApiLib.PortableDeviceClass();

        public int CloseSession(){           
            IPortableDevicePropVariantCollection pvc = (IPortableDevicePropVariantCollection)new PortableDeviceTypesLib.PortableDevicePropVariantCollectionClass();
            IPortableDeviceValues pParameters = (IPortableDeviceValues)new PortableDeviceTypesLib.PortableDeviceValuesClass();
            PortableDeviceApiLib.IPortableDeviceValues pResults; int result;

            pParameters.SetGuidValue(ref PortableDevicePKeys.WPD_PROPERTY_COMMON_COMMAND_CATEGORY, ref ZuneDevicePKeys.ZUNE_COMMMAND_A12.fmtid);
            pParameters.SetUnsignedIntegerValue(ref PortableDevicePKeys.WPD_PROPERTY_COMMON_COMMAND_ID, ZuneDevicePKeys.ZUNE_COMMMAND_A12.pid);
            pParameters.SetUnsignedIntegerValue(ref ZuneDevicePKeys.ZUNE_GetDeviceInfo, 0x9216);
            pParameters.SetIUnknownValue(ref ZuneDevicePKeys.ZUNE_OpenSession, pvc);
            pPortableDevice.SendCommand(0, pParameters, out pResults);

            pResults.GetErrorValue(ref PortableDevicePKeys.WPD_PROPERTY_COMMON_HRESULT, out result);

            //pPortableDevice.Close();

            return result;
        }
    }
}
